﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Utility
{
    public class LogHelper
    {
        private static readonly string _Log4netXmlConfigFilePath = (System.Configuration.ConfigurationManager.AppSettings["Log4netXmlConfigFilePath"] == null) ? "" : System.Configuration.ConfigurationManager.AppSettings["Log4netXmlConfigFilePath"].ToString();

        static LogHelper()
        {
            log4net.Config.XmlConfigurator.Configure(new FileInfo(_Log4netXmlConfigFilePath));
        }

        public static void Write(string msg)
        {
            if (!File.Exists(_Log4netXmlConfigFilePath))
            {
                throw new Exception("未找到Log4net配置文件：" + _Log4netXmlConfigFilePath);
            }

            log4net.ILog log = log4net.LogManager.GetLogger("ApplicationInfoLog");
            log.Info(msg);
        }

        public static void Debug(object message, Exception ex)
        {
            if (!File.Exists(_Log4netXmlConfigFilePath))
            {
                throw new Exception("未找到Log4net配置文件：" + _Log4netXmlConfigFilePath);
            }

            log4net.ILog log = log4net.LogManager.GetLogger("ApplicationInfoLog");
            log.Debug(message, ex);
        }



    }//
}//
